<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="k" uri="/WEB-INF/k.tld"%>
<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>怀才进销存管理软件 - 销售前台</title>
		<jsp:include page="../inc.jsp"></jsp:include>
		<script type="text/javascript" src="../My97DatePicker/WdatePicker.js"></script>
		<script type="text/javascript" src="../jslib/date.js"></script>
		<link href="../web/css/style.css" rel="stylesheet" type="text/css" />
		<SCRIPT language="JavaScript" type="text/javascript" src="../web/js/hdm.js"></SCRIPT>
		<SCRIPT>
		var calendar;
		var datagrid;
		$(function(){
			$('#d4313').val((new Date()).pattern("yyyy-MM-01"));
		    $('#d4314').val((new Date()).pattern("yyyy-MM-dd"));
			datagrid = $('#datagrid').datagrid({
				url : '${pageContext.request.contextPath}/xsgl/salelistAction!datagridsettlementTotal.html',
				title : '对账明细列表',
				iconCls : 'icon-save',
				pagination : true,
				pagePosition : 'bottom',
				pageSize : 10,
				pageList : [ 10, 20, 30, 40 ],
				fit : true,
				fitColumns : false,
				nowrap : false,
				border : false,
				idField : 'id',
				//sortName : 'id',
				//sortOrder : 'desc',
				checkOnSelect : false,
				selectOnCheck : true,
				//frozenColumns : [ [ {
				//	title : '编号',
				//	field : 'id',
				//	width : 150,
				//	sortable : true,
				//	hidden : true
				//} ] ],
				columns : [ [  {
					title : '营业员',
					field : 'uusername',
					width : 150,
					align:'center'
				}, {
					title : '所属仓库',
					field : 'rname',
					width : 150,
					align:'center'
				}, {
					title : '开始时间',
					field : 'beginDate',
					width : 150,
					align:'center',
					formatter : function(value, row, index) {
						return value.substring(0,10);
					}
				}, {
					title : '结束时间',
					field : 'endDate',
					width : 150,
					align:'center',
					formatter : function(value, row, index) {
						return value.substring(0,10);
					}
				} , {
					title : '对账总金额',
					field : 'total',
					width : 150,
					align:'center'
				}] ],
				/* onLoadSuccess : function(data){
					alert(JSON.stringify(data));
				},	 */		
				onRowContextMenu : function(e, rowIndex, rowData) {
					e.preventDefault();
					$(this).datagrid('unselectAll');
					$(this).datagrid('selectRow', rowIndex);
					$('#menu').menu('show', {
						left : e.pageX,
						top : e.pageY
					});
				}
			});
			
			var srid = $('#searchForm').find('input[name=srid]');
			var sridCombobox = srid.combobox({
				url : '${pageContext.request.contextPath}/rkgl/repertoryAction!noAuth_combobox.html',
				valueField : 'id',
				textField : 'name',
				multiple : false,
				editable : false,
				panelHeight : 'auto'
			});
			
			calendar = $('#calendar').calendar({
				fit : true,
				current : new Date(),
				border : false,
				onSelect : function(date) {
					$(this).calendar('moveTo', new Date());
				}
			});
			
			$('#beginDate').val('${BeginAudit}');
			$('#endDate').val((new Date()).pattern("yyyy-MM-dd"));
			
		});
			
		function logout(){
			sy.messagerConfirm('请确认', '您确定要退出前台销售？', function(r) {
				if(r){
					$.ajax({
						url : '${pageContext.request.contextPath}/loginAction!logout.html',
						type : 'get',
						success:function(){
							self.location.reload();
							if(window.opener){
								opener.location = opener.location;
							}
							window.close();
						}
					});
				}
			});
		}
		
		function _querysearch() {
			$('#queryForm').form('submit', {
				url : '${pageContext.request.contextPath}/xsgl/statistic!noAuth_statistic.html',
				success : function(d) {
					var json = $.parseJSON(d);
					if(json.msg){
						parent.sy.messagerAlert('提示', json.msg, 'error');
						$('#total').html(0.0);
					}else
						$('#total').html(json.obj);
				}
			});
		}
		
		function _settlement(){

			//判断日期，结算的日期不能大于当前的日期
		

			var _endDate=$('#endDate').val();
			var _day=new Date().format("yyyy-MM-dd");

			if(_endDate!=_day){

				if(compareDate(new Date().format("yyyy-MM-dd"),_endDate)){
					alert("结算结束日期不能大于当前日期！");
					return;
				}
				
			}
				
  
			
			$('#queryForm').form('submit', {
				url : '${pageContext.request.contextPath}/xsgl/salelistAction!noAuth_settlement.html',
				success : function(d) {
					var json = $.parseJSON(d);
					sy.messagerShow({
						msg : json.msg,
						title : '提示'
					});
					self.location.reload();
				}
			});
		}

		//日期比较大小 的d2>d1
	    function compareDate(d1,d2)
        {

                 var arrayD1 = d1.split("-");

                 var date1 = new Date(arrayD1[0],arrayD1[1],arrayD1[2]);

                 var arrayD2 =d2.split("-");

                 var date2 = new Date(arrayD2[0],arrayD2[1],arrayD2[2]);

                 if(date1 > date2) return false;         

                 return true;

        }
		
	function _search() {
		datagrid.datagrid('load', sy.serializeObject($('#searchForm')));
	}
	
	function cleanSearch() {	    
		datagrid.datagrid('load', {});
		$('#searchForm input').val('');
	}


	Date.prototype.format = function(format)
	{
	 var o = {
	 "M+" : this.getMonth()+1, //month
	 "d+" : this.getDate(),    //day
	 "h+" : this.getHours(),   //hour
	 "m+" : this.getMinutes(), //minute
	 "s+" : this.getSeconds(), //second
	 "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
	 "S" : this.getMilliseconds() //millisecond
	 }
	 if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
	 (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	 for(var k in o)if(new RegExp("("+ k +")").test(format))
	 format = format.replace(RegExp.$1,
	 RegExp.$1.length==1 ? o[k] :
	 ("00"+ o[k]).substr((""+ o[k]).length));
	 return format;
	}
	
		</SCRIPT>
	</head>

	<body>
		<div class="top">
			<div class="logo">
				<img src="../web/imgs/htlogo.jpg" width="480" height="47" />
			</div>
			<div class="right">
				欢迎您！${sessionInfo.loginName} [${sessionInfo.roleNames}]
				<a href="javascript:void(0)" onclick="logout()">退出登录</a>
				<!-- 
					<a href="#">修改密码</a>
				 -->
			</div>
		</div>
		<div class="content">
			<div class="right">
				<!--日历标题-->
				<div class="title">
					<img src="../web/imgs/pic1.gif" width="6" height="6" />
					日历
				</div>
				<!--/日历标题-->
				<!--日历-->
				<div style="height: 180px;">
					<div id="calendar"></div>
				</div>
				<!--/日历-->
				<!--公告+提醒-->
				<div class="title">
					<ul>
						<li id="cp1" class="cpover" onMouseOver="setTab_('cp',1,5,'cpover')">
							公告<span class="tabRefresh"><a href="javascript:void(0);" onclick="javascript:document.frames('announcementIframe').location.reload()" class="icon-mini-refresh"></a></span>
						</li>
						<li id="cp2" onMouseOver="setTab_('cp',2,5,'cpover')">
							系统提醒<span class="tabRefresh"><a href="javascript:void(0);" onclick="javascript:document.frames('warnIframe').location.reload()" class="icon-mini-refresh"></a></span>
						</li>
					</ul>
				</div>
				<div class="conts">
					<div id="cp_con1">
						<iframe width="100%" height="400px;" scrolling="auto" frameborder="0" onload="javascript:void(0);" name="announcementIframe" id="announcementIframe" src="${pageContext.request.contextPath}/qtmk/announcementAction!noAuth_tabAnnounce.html"></iframe>
					</div>
					<div id="cp_con2" style="display: none;">
						<iframe width="100%" height="400px;" scrolling="no"  frameborder="0" onload="javascript:void(0);" name="warnIframe" id="warnIframe" src="${pageContext.request.contextPath}/qtmk/remindWarnAction!noAuth_tabRemindWarn.html"></iframe>
					</div>
				</div>
				<!--/公告+提醒-->
			</div>
			<div class="left">
				<div class="nav">
					<ul>
						<k:security key="XSGL_QTXS">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/sale.html">
								<img src="${pageContext.request.contextPath}/web/imgs/navxsgl.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_XSTH">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/saleReturn.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-xsth.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_KCCX">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/amount.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-kcgl.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_HYGL">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/member.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-hygl.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_RJQS">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/settlement.html">
								<img src="${pageContext.request.contextPath}/web/imgs/nav-rjqs.jpg" width="104" height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_XSJLCX">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/salelist.html">
								<img src="../web/imgs/navxsglcx.jpg"  height="35" /> 
							</a>
						</li>
						</k:security>
						<k:security key="XSGL_THJLCX">
						<li>
							<a href="${pageContext.request.contextPath}/xsgl/saleReturnlist.html">
								<img src="../web/imgs/navthglcx.jpg" height="35" /> 
							</a>
						</li>
						</k:security>
					</ul>
				</div>
				<div class="cont">
					<div style="overflow: hidden;" align="center" style="width:100%">
						<form id="queryForm" style="width: 100%">
							<table  style="width: 100%">
								<tr>
									<th align="right" >
										上一次结算时间
									</th>
									<td class="p_l" align="left">
										${EndAudit }
									</td>
								</tr>
								<tr>
									<th align="right" >
										结&nbsp;&nbsp;算&nbsp;&nbsp;仓&nbsp;&nbsp;库
									</th>
									<td class="p_l" align="left">
										<select name="rid" class="width1" id="rid"
											style="width: 200px;">
											<c:forEach items="${VRepertories}" var="VRepertory">
												<option value='${VRepertory.id }'
													<c:if test="${VRepertory.id eq rid }">selected="selected"</c:if>>
													${VRepertory.name }
												</option>
											</c:forEach>
										</select>
									</td>
								</tr>
								<tr>
									<th align="right" >
										结&nbsp;&nbsp;算&nbsp;&nbsp;时&nbsp;&nbsp;间
									</th>
									<td class="p_l" align="left">
										<input class="Wdate" name="beginDate" id="beginDate"
											onclick="WdatePicker()" readonly="readonly" />
										<input onclick="WdatePicker()" class="Wdate"
											readonly="readonly" name="endDate" id="endDate" />
										<input type="button" value="统计" onclick="_querysearch()" />
									</td>
									
								</tr>
								<tr>
									<th align="right" >
										尚需&nbsp;结算&nbsp;金额
									</th>
									<td class="p_l" style="color: #033E7A;line-height: 35px;">
										<div style="text-align: left;">
											<h1 style="float: left;display: block;min-width:215px ">
												<span id="total">${total }</span>元
											</h1>
											
											<div style="float:left;">
												<input type="button" value="结算" onclick="_settlement()" class="button2 dis_block fl m_l bornon"/>
											</div>
										</div>
										
									</td>
								</tr>
					
							</table>
						</form>
					</div>
					<div data-options="region:'south',border:false,title:'过滤条件'" style="height: 29px;overflow: hidden;" align="left">
					<form id="searchForm">
						<table class="tableForm datagrid-toolbar" style="width: 100%;height: 100%;">
							<tr>
								 <th style="width:60px;">营业员</th>
								<td style="width:16px;"><input name=uusername style="width:110px;" /></td>
								<th style="width:60px;">所属仓库</th>
								<td style="width:16px;"><input name="srid" style="width: 110px;" /></td>
								<th style="width:60px;">开始时间</th>
								<td style="width:16px;"> 					  
								<input id="d4313" name="beginDate" class="easyui-validatebox" data-options="required:'true',missingMessage:'请选择销售时间'" style="width: 110px;" onClick="WdatePicker()" onFocus="WdatePicker({maxDate:'#F{$dp.$D(\'d4314\')||\'2030-10-01\'}'})"/></td>
								<th style="width:60px;">结束时间</th>
								<td style="width:16px;">					 
								<input id="d4314" name="endDate"   class="easyui-validatebox" data-options="required:'true',missingMessage:'请选择销售时间'" style="width: 110px;" onClick="WdatePicker()" onFocus="WdatePicker({minDate:'#F{$dp.$D(\'d4313\')}',maxDate:'2030-10-01'})"/></td>
								
								<td><a href="javascript:void(0);" class="easyui-linkbutton" onclick="_search();">查询</a><a href="javascript:void(0);" class="easyui-linkbutton" onclick="cleanSearch();">清空</a></td>
							</tr>
						</table>
					</form>
					</div>
					<div data-options="region:'center',border:false" style="height: 360px;overflow: hidden;">
						<table id="datagrid"></table>
					</div>
				</div>
			</div>
		</div>
			
		<br><br><br>
		<div class="foot" style="overflow: hidden;" align="justify">
			Copyright @ 2013
			<a style="color:#FFFFFF; text-decoration:none;" target="_blank" href="http://www.miitbeian.gov.cn">浙ICP备13002014号-1</a>
			<br>
			杭州怀才商贸有限公司 服务电话：0571-28030726
		</div>
	</body>
</html>
